package com.wanxi.controller.front;

import com.wanxi.domain.ResultModel;
import com.wanxi.domain.product.ProductModel;
import com.wanxi.service.front.DisplayService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RequestMapping("front")
@RestController
@CrossOrigin(allowCredentials = "true", origins = "http://localhost:63342", allowedHeaders = "*")//允许跨域请求
public class DisplayController {


    @Autowired
    private DisplayService displayService;

    /*查询产品总条数*/
    @GetMapping("productSum")
    public int getProductCount() {

        int resultModel = displayService.getFrontCount();

        return resultModel;
    }

    //跟据类型查询产品数量
    @GetMapping("findByCategory")
    public List<ProductModel> getInfoByTypeName(
            @RequestParam("typeName") String typeName,
            @RequestParam("page") int page,
            @RequestParam("limit") int limit) {

        page = (page - 1) * limit;

        List<ProductModel> resultModel = displayService.findByTypeName(typeName, page, limit);

        return resultModel;
    }

    /*根据产品类型查询产品数量*/
    @GetMapping("productTypeSum")
    public int getCountByTypeName(@RequestParam("typeName")String typeName){
        int resultModel = displayService.getCountType(typeName);

        return resultModel;
    }

    /*产品详情页面的上下页产品*/
    @GetMapping("switch")
    public List<ProductModel>  getSwitch(int id){

        List<ProductModel>  resultModel = displayService.findSwitchInfo(id);

        return resultModel;
    }
}
